<template>
    <h2>修改页面</h2>
    <table>
        <tr>
            <td>
                借款款项名称
            </td>
            <td>
                <input type="text" v-model="R_Name" id="R_Name">
            </td>
        </tr>
        <tr>
            <td>
                借款最高金额
            </td>
            <td>
                <input type="text" v-model="R_Max" id="R_Max">
            </td>
        </tr>
        <tr>
            <td>
                借款最高年限
            </td>
            <td>
                <input type="text" v-model="R_Year" id="R_Year">
            </td>
        </tr>
        <tr>
            <td>
                利息编号
            </td>
            <td>
                <select v-model="I_Id">
                    <option value="0">--请选择--</option>
                    <option v-for="item in data" :value="item.I_Id">{{ item.I_Interest }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                借款款项简介
            </td>
            <td>
                <textarea v-model="R_Dess" id="R_Dess"></textarea>
            </td>
        </tr>
        <tr>
            <td>

            </td>
            <td>
                <input type="button" value="修改" @click="Upa">
            </td>
        </tr>

    </table>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { onMounted } from 'vue';
import axios from 'axios';
import { useRoute } from 'vue-router';

const route = useRoute();
const R_Name = ref('');
const R_Max = ref();
const R_Year = ref('');
const I_Id = ref(0);
const R_Dess = ref('');
const R_Id = route.params.R_Id;

const data = ref([]);
onMounted(() => {
    Bind()
    axios.get('http://localhost:52545/api/Demo/Fan', {
        params: {
            R_Id: R_Id
        }
    })
        .then(res => {
            R_Name.value = res.data.R_Name;
            R_Max.value = res.data.R_Max;
            R_Year.value = res.data.R_Year;
            I_Id.value = res.data.I_Id;
            R_Dess.value = res.data.R_Dess;

        })
})
const Bind = () => {
    axios.get('http://localhost:52545/api/Demo/Bind')
        .then(res => {
            data.value = res.data;
        })
        .catch(error => {
            console.log(error);
        })
}

const Upa = () => {
    axios.post('http://localhost:52545/api/Demo/Upa', {
        R_Name: R_Name.value,
        R_Max: R_Max.value,
        R_Year: R_Year.value,
        I_Id: I_Id.value,
        R_Dess: R_Dess.value,
        R_Id: R_Id
    })
        .then(res => {
            if (res.data > 0) {
                alert("修改成功");
                location.href = '/RShow'
                return;
            }
            else {
                alert("修改失败");
            }
        })
}
</script>